function airPortPickDoor(that,e) {
    console.log('js入口',e);
    if (e.currentTarget.dataset.name) {
        that.setData({
            areaPickTag: e.currentTarget.dataset.name,
            airPortType:e.currentTarget.dataset.name
        })
    }
    if(e.type == 'move' && e.currentTarget.dataset.stopMove){
        return;
    }

    var mothod = e.currentTarget.dataset.mothod
    if (mothod == 'cascadeDismissAir') {
        cascadeDismissAir(that, e);
    } else if (mothod == 'loadAirportList') {
        loadAirportList(that, e);
    } else if (mothod == 'loadedAirPort') {
        loadedAirPort(that, e);
    } else if (mothod == 'showAirPick') {
        showAirPick(that, e);
    } 
}

// 机场选择器miss
function cascadeDismissAir(that,e) {
    console.log('收回弹框');
    that.animation.translateY(285).step();
    that.setData({
        airPortpickData:{
            animationDataAir: that.animation.export(),
         maskVisualAir: 'hidden',
        }
        
    });
}

//加载机场列表数据
//传递进来的是文本框控件，根据文本框判断机场是上车还是下车
//然后取不同地城市id，根据城市id获取机场(获取城市前缀)
//给城市id和省id都进行赋值，再判断城市id是否为空，为空就说明只选择了省，这是根据省进行查找
function loadAirportList(that,e) {
    var prefix  = e.currentTarget.dataset.airPortByArea;    //前缀 标记机场与之绑定的文本框
    var cityid;
    var meth;
    var ProvinceIDPath = prefix+'Province';
    var CityIDPath = prefix+'City';
    if(that.data[ProvinceIDPath]){
        meth = '4';
        cityid = that.data[ProvinceIDPath];
    }
    if(that.data[CityIDPath]){
        meth = '6';
        cityid = that.data[CityIDPath];
    }
    if(!cityid || cityid.length == 0 || cityid == null){
        wx.showToast({
            title: '请选择对应城市',
        })
        return;
    }
    console.log('meth',meth);
    wx.showToast({
        title: '加载机场中...',
        icon: 'loading',
        duration: 10000
    })
    wx.request({
        url: 'https://www.lanshuicar.com/Server/ByIDAddress.ashx',
        data: {
            Meth: meth,
            ID: cityid
        },
        method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        // header: {}, // 设置请求的 header
        success: function (res) {
            console.log('获取机场',res,that.data);
            loadedAirPort(that, e.target.id, res.data.data);
        },
        fail: function () {
            // fail
        },
        complete: function () {
            wx.hideToast();
            console.log('获取机场完成');
        }
    })

}
//为机场数据源赋值
function loadedAirPort(self, id, airPorts) {
    var arr = new Array();
    for (var i = 0; i < airPorts.length; i++) {
        arr.push(airPorts[i].aAPName);
    }
    console.log(self, '机场s', airPorts);
    if (arr.length == 0) {
        wx.showModal({
            title: '提示',
            content: '这个城市暂无机场',
            showCancel: false,
            confirmText: '知道了',
            success: function (res) {
            }
        })
        return;
    }
    var AirPortArr = {AirPortArr:arr};
    showAirPick(self, id);
    setData(self,AirPortArr);
   
}

//显示机场控件 e:机场的文本控件
function showAirPick(that, id) {
    var animation = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-in-out',
    });
    that.animation = animation;
    animation.translateY(-285).step();
    that.setData({
        airPortpickData:{
            animationDataAir: that.animation.export(),
            maskVisualAir: 'show',
        }
    });
    console.log('显示机场',that);
}



/*************************************************************/
//合并两个json数据，并覆盖相同属性
function mergeJson(jsonbject1, jsonbject2) {
    var resultJsonObject = {};
    for (var attr in jsonbject1) {
        resultJsonObject[attr] = jsonbject1[attr];
    }
    for (var attr in jsonbject2) {
        resultJsonObject[attr] = jsonbject2[attr];
    }
    return resultJsonObject;
};

function setData(that, newAreaData) {
    var areaData = mergeJson(that.data.airPortpickData, newAreaData);
    console.log('合并后数据',areaData);
    that.setData({
        airPortpickData: areaData
    })
    console.log('为机场列表赋值完成',that);
    return that.data.airPortpickData;
}

module.exports.airPortPickDoor = airPortPickDoor;
module.exports.cascadeDismissAir = cascadeDismissAir